package nix.bs.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import nix.bs.domain.User;

public class BsLoginFilter implements Filter {

	public void destroy() {

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		HttpServletRequest req = (HttpServletRequest) request;
		User user = (User) req.getSession().getAttribute("session_user");
		if (user != null) {
			chain.doFilter(request, response);
		} else {
			req.setAttribute("msg", "对不起，您还没有登录！");
			req.getRequestDispatcher("/bs/jsps/user/login.jsp").forward(req,
					response);
		}
	}

	public void init(FilterConfig fConfig) throws ServletException {

	}

}
